package cn.woochen.comlib.jsbridge

import android.webkit.WebView
import cn.woochen.comlib.util.FileUtils

/**
 * webview桥接工具类
 */
object WebBridgeUtil {

    /**
     * 本地js文件
     */
    const val JAVA_SCRIPT = "WebViewJavascriptBridge.js"
    const val CALLBACK_ID_FORMAT = "JAVA_CB_%s"
    const val JS_HANDLE_MESSAGE_FROM_JAVA = "javascript:WebViewJavascriptBridge._handleMessageFromNative('%s');"

    fun webViewLoadLocalJs(view: WebView, jsPath: String?) {
        if (jsPath.isNullOrBlank()) return
        val jsContent = FileUtils.assetFile2Str(view.context, jsPath)
        view.loadUrl("javascript:$jsContent")
    }


}